package edu.spec.student.service.impl;

import edu.spec.student.dao.iface.ICourseDao;
import edu.spec.student.model.Course;
import edu.spec.student.service.iface.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by MadFrog on 2017/10/13.
 */
@Service
public class CourseService implements ICourseService {

    @Autowired
    private ICourseDao courseDao;

    @Override
    public void add(Course c) {
        courseDao.add(c);
    }

    @Override
    public String delete(Integer id) {
        // TODO 判断课程有没有被使用
        //  loadLessonByCourse
        courseDao.delete(id);
        return "";
    }

    @Override
    public void update(Course c) {
        Course dbc = courseDao.load(c.getId());
        dbc.setName(c.getName());
        courseDao.update(dbc);
    }

    @Override
    public Course load(Integer id) {
        return courseDao.load(id);
    }

    @Override
    public List<Course> listCourseByTeacher(Integer id) {
        return courseDao.listCourseByTeacher(id);
    }
}
